package com.acme.bankapp.service.bank;

import java.io.File;
import java.io.IOException;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.exceptions.ClientExistsException;
import com.acme.bankapp.exceptions.FeedLoaderException;
import com.acme.bankapp.exceptions.IllegalAmountArgumentException;


public class BankAplication {
	
	public static File dataBaseFile = new File ("bankSerial.dbs");
	
	public static void main(String[] args) throws IllegalAmountArgumentException, ClientExistsException, FeedLoaderException, IOException, ClassNotFoundException {
		
		Bank deutscheBank = new Bank("Deutsche Bank");
		
		for(int i=0; i<args.length; i++){
			if (args[i].equals("-loadfeed") && i+1 < args.length ){
				File feedFile = new File( args[i+1] );
				if (feedFile.isFile()){
					BankDataLoaderService.getClientsFromFeed(deutscheBank, feedFile);
				}else{
					System.out.println( feedFile.getAbsolutePath() + " is missing");
				}
			}
			if (args[i].equals("-loadbank") && i+1 < args.length ){
				if (new File( args[i+1] ).isFile()){
					dataBaseFile = new File( args[i+1] );
					deutscheBank = BankService.readBank(dataBaseFile);
				}else{
					System.out.println( dataBaseFile.getAbsolutePath() + " is missing");
				}
			} 
		}
		
		BankService.showBank(deutscheBank);
	}
}